<?php 

Class announController extends appController
{
	
	public function index()
	{
		$page=isset($_REQUEST['page'])?intval($_REQUEST['page']):'';
		$an_list=Model('announ')->anList($page);
		$this->assign('ur_here','>公告管理');
		$this->assign('search_action','index.php?g=admin&m=announ&a=search');
		$this->assign('an_list',$an_list['data']);
		$this->assign('user_list_page',$an_list['pagelink']);
		$this->display('index.html');
		
	}
	public function ordering()
	{
		$id=isset($_POST['id'])?intval($_POST['id']):'';
		$val=isset($_POST['val'])?intval($_POST['val']):'';
		$result=Model('announ')->ordering($val,$id);
		print_r(json_encode($result));
	}
	public function search()
	{
		$page=isset($_REQUEST['page'])?intval($_REQUEST['page']):'';
		$keyword=isset($_GET['k'])?trim($_GET['k']):'';
		$an_list=Model('announ')->search_an($page,$keyword);
		$this->assign('ur_here','>公告管理');
		$this->assign('search_action','index.php?g=admin&m=announ&a=search');
		$this->assign('an_list',$an_list['data']);
		$this->assign('user_list_page',$an_list['pagelink']);
		$this->display('index.html');
	
	}
	public function edit()
	{
		$this->assign('ur_here','>编辑公告');
	    $id=isset($_REQUEST['id'])?$_REQUEST['id']:'';
		$announ=Model('announ')->getDetail($id);
		$this->assign('action','update');
		$this->assign('announ',$announ);
		$this->assign('id',$id);
		$this->display('add.html');
	
	}
	public function update()
	{
		$id=isset($_POST['id'])?$_POST['id']:'';
		
		$info['title']=isset($_POST['title'])?$_POST['title']:'';
		$info['content']=isset($_POST['content'])?$_POST['content']:'';
		$info['url']=isset($_POST['url'])?$_POST['url']:'';
		$info['is_show']=isset($_POST['is_show'])?$_POST['is_show']:'';
		
		if($info['url']!='')
		{
			unset($info['content']);
		}
		else
		{
			unset($info['url']);
		}
		
		if(Model('announ')->modified($info,$id))
		{
			$this->showMsg(Lang('SUCCESS_EDIT'),'index.php?g=admin&m=announ&a=index');
		}
		else
		{
			$this->showMsg(Lang('INVALID_OPERATION'),'index.php?g=admin&m=announ&a=index');
		}
	}
	public function add()
	{
	
		$this->assign('ur_here','>添加公告');
		$this->assign('action','insert');
		$this->display('add.html');
	
	}
	public function del()
	{
		
		$id=isset($_REQUEST['id'])?$_REQUEST['id']:'';
		
		if(is_array($id))
		{
			foreach($id as $k=>$v)
			{
				$result=Model('announ')->del_an($v);
				
			}
		}
		else
		{
			$result=Model('announ')->del_an($id);
		}
		print_r(json_encode($result));
	}
	public function insert()
	{
	
	   $info['title']=isset($_POST['title'])?$_POST['title']:'';
	   
		$info['content']=isset($_POST['content'])?$_POST['content']:'';
		$info['url']=isset($_POST['url'])?$_POST['url']:''; 
		$info['is_show']=isset($_POST['is_show'])?$_POST['is_show']:'';
		
		if($info['url']!='')
		{
			unset($info['content']);
		}
		else 
		{
			unset($info['url']);
		}
		
		if(Model('announ')->publish($info))
		{
			$this->showMsg(Lang('SUCCESS_ADD'));
		}
		else
		{
			$this->showMsg(Lang('INVALID_OPERATION'));
		}
	
	}
	
	
	
}